<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>药库供应商</title>
<script type="text/javascript" src="../static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="../static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/easyui/themes/metro-red/easyui.css">
</head> 
<body> 
<script type="text/javascript">
$(function(){
	//验证手机号
	$.extend($.fn.validatebox.defaults.rules, {
		brdh:{
			validator: function(value, param){
				//自定义正则验证,密码验证
				var reg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
				return reg.test(value);
			},
			message:'电话号码格式错误'
		},
	});
	
	//验证名字
	$.extend($.fn.validatebox.defaults.rules, {
	   	 brdz:{
	             validator: function(value, param){
	               //自定义正则验证,密码验证
	               var reg = /^[\u4E00-\u9FA5A-Za-z0-9_]+$/;
	               return reg.test(value);
	             },
	             message:'名称格式错误'
	       },
	   });
});

//时间转换
function comformatDate(date) {
	var day = new Date(date); 
	var Year = 0; 
	var Month = 0; 
	var Day = 0; 
	var CurrentDate = ""; 
	//初始化时间 
	Year= day.getFullYear();//
	Month= day.getMonth()+1; 
	Day = day.getDate(); 
	Hour = day.getHours(); 
	 Minute = day.getMinutes(); 
	 Second = day.getSeconds(); 
	CurrentDate += Year + "-"; 
	if (Month >= 10 ) { 
		CurrentDate += Month + "-"; 
	}else { 
		CurrentDate += "0" + Month + "-"; 
	} 
	if (Day >= 10 ) { 
		CurrentDate += Day ; 
	}else { 
		CurrentDate += "0" + Day ; 
	} 
	if(Hour>=10){
		CurrentDate +=" "+Hour;
	}else{
		CurrentDate +=" "+"0"+Hour;
	}
	if(Minute>=10){
		CurrentDate +=":"+Minute;
	}else{
		CurrentDate +=":"+"0"+Minute;
	}
	if(Second>=10){
		CurrentDate +=":"+Second;
	}else{
		CurrentDate +=":"+"0"+Second;
	}
	return CurrentDate; 
};
		
		//添加药品展示列表
		$(function(){
			$('#gongyingshang').datagrid({
			    url:'gysbiaoge',
			    pagination:true,
			    pageNumber:1,
			    pageSize:5,
			    pageList:[5,10],
			    columns:[[			    	
			    	{field:'',checkbox:true,width:"157px",align:'center'},
					{field:'factoryId',title:'编号',width:"157px",align:'center'},
					{field:'factoryName',title:'供应商名称',width:"157px",align:'center'},
					{field:'factoryPeople',title:'联系人',width:"157px",align:'center'},
					{field:'factoryPhone',title:'联系电话',width:"157px",align:'center'},
					{field:'factoryCreationDate',title:'创建日期',width:"157px",align:'center',formatter:comformatDate},
					{field:'caozuo',title:'操作',width:157,align:'center',
						formatter:function(value,row,index){
							return "<input type='button' style='background:#E4F1FB;color:#2779AA;border:none' onclick='bianji("+row.factoryId+")' value='查看详情'/>";
						}	
					}
			    ]]			       
			});
		});
		
		//供应商新增事件
		$(function(){
			$("#baocunanniu").click(function(){
				//供应商名称
				var factoryName=$("#factoryName").val();
				//联系人
				var factoryPeople=$("#factoryPeople").val();
				//电话
				var factoryPhone=$("#factoryPhone").val();
				if(factoryName==''){
					$.messager.confirm('','名称输入不能为空',{
						
					});
				}else if(factoryPhone==''){
					$.messager.confirm('','电话输入不能为空',{
						
					});
				}else if(!(/^[\u4E00-\u9FA5A-Za-z0-9_]+$/).test(factoryName)){
					$.messager.alert("温馨提示：","名称格式错误！");
				}else if(!(/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/).test(factoryPhone)){
					$.messager.alert("温馨提示：","电话号码格式错误！");
				}else{
					$.ajax({
					    url:'gysxz',
					    type : "post",
					    data : {
					    	"factoryName":factoryName,
					    	"factoryPeople":factoryPeople,
					    	"factoryPhone":factoryPhone
					    },			    
					    success:function(data){					    	
					    	$.messager.show({
								title:'提 示',
								msg:'供应商新增成功！！！！',
								height:200,
								timeout:1000,
								showType:'slide'
							});
					    	//供应商名
							$("#factoryName").textbox('setValue',null);
							//联系人
							$("#factoryPeople").textbox('setValue',null);
							//联系电话
							$("#factoryPhone").textbox('setValue',null);
							//创建日期
							$("#factoryCreationDate").textbox('setValue',null);
							$("#gongyingshang").datagrid("reload");//刷新表格
					    }
					});
				}
			});
		}); 
		//查看详情
		function bianji(id){
			var row=$('#gongyingshang').datagrid('getSelected');
			var id = row["factoryId"];//供应商id
			//alert(id);
			var gname = row["factoryName"];//供应商名称
			var rname = row["factoryPeople"];//供应商联系人
			var gysdian = row["factoryPhone"];//联系人电话
			
			//把值放在文本框里
			$("#bianhao").textbox("setValue",id);
			$("#gname").textbox("setValue",gname);
			$("#lxrname").textbox("setValue",rname);
			$("#lxdhua").textbox("setValue",gysdian);
				
			$("#gongyingshang").datagrid("reload");//刷新
			$("#gongyingshangtianjia").window("open");//打开修改界面
		}
		
		//编辑确定
		$("#queding2").click(function(){
			var idd = $("#bianhao").val();
			var fname = $("#gname").val();
			var rname = $("#lxrname").val();
			var dianhua = $("#lxdhua").val();
			$.ajax({
				url : 'xiugai',
				type : 'post',
				data : {"idd":idd,"fname":fname,"rname":rname,"dianhua":dianhua},
				success : function(data){
					$("#gongyingshang").datagrid("reload");//刷新
					alert("修改成功！！！")	
				}
			})
			$("#gongyingshangtianjia").window("close");
		});
</script>

		 <div class="easyui-layout" style="padding:20px;border:solid 1px #19AA8D;border-radius:5px;width:1000px;margin-left:60px;margin-top:10px;">
 		 	<input class="easyui-textbox" id="factoryName" data-options="label:'供应商名：',width:230,labelAlign:'right'">
 		 	<input class="easyui-textbox" id="factoryPeople" data-options="label:'联系人：',width:230,labelAlign:'right'">
			<input class="easyui-textbox" id="factoryPhone" data-options="label:'联系电话：',width:230,labelAlign:'right'">
		 	<input class="easyui-datetimebox" id="factoryCreationDate" data-options="required:true,showSeconds:false,label:'创建日期：',width:230,labelAlign:'right'">
			<a id="baocunanniu" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true" style="margin-left:850px;margin-top:15px;">确定</a>
		 </div>	
		 
		

	<!-- 添加的药品列表数据 -->
	<div style="margin-top:20px;">
	<table id="gongyingshang" class="easyui-datagrid" data-options="fitColumns:true" style="padding:15px;height:300px;"></table> 
	 </div>
	<!-- 修改供应商界面 -->
	<div id="gongyingshangtianjia" class="easyui-window" title="修改信息" style="width:380px;height:350px;" data-options="iconCls:'icon-add',closed:true"> 
		 	<div style="text-align:center;margin-top:15px;">
		 		<input class="easyui-textbox" id="bianhao" data-options="label:'编号：',width:260,labelAlign:'right',disabled:true">
		 	</div>
		 	
		 	<div style="text-align:center;margin-top:15px;">
		 		<input class="easyui-textbox" id="gname" data-options="label:'供应商名：',width:260,labelAlign:'right'">
		 	</div>
		 	<div style="text-align:center;margin-top:15px;">
		 		<input class="easyui-textbox" id="lxdhua" data-options="label:'联系电话：',width:260,labelAlign:'right'">
		 	</div>
		 	<div style="text-align:center;margin-top:15px;">
		 		<input class="easyui-textbox" id="lxrname" data-options="label:'联系人：',width:260,labelAlign:'right'">
		 	</div>		 	
		 	
		 	<div style="text-align:center;margin-top:15px;">
		 		<a class="easyui-linkbutton" id="queding2" data-options="iconCls:'icon-ok',plain:true">确定</a>
		 	</div>
	</div>
</body>
</html>